package com.sc.nft.dao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.sc.nft.enums.TransferCollectionWithoutStatusEnum;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.TransferCollectionWithoutRecords;
import com.sc.nft.mapper.TransferCollectionWithoutRecordsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 转增到外部记录表(sc_transfer_collection_without_records)数据DAO
 *
 * @author Sun
 * @since 2024-05-18 13:13:49
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class TransferCollectionWithoutRecordsDao extends ServiceImpl<TransferCollectionWithoutRecordsMapper, TransferCollectionWithoutRecords> {

    public void updateStatusByUserCollectionChainId(Long userCollectionChainLogId,TransferCollectionWithoutStatusEnum status,String mateUniverseTransactionHash,String mateWalletTransactionHash) {
        LambdaUpdateWrapper<TransferCollectionWithoutRecords> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(TransferCollectionWithoutRecords::getUserCollectionChainLogId, userCollectionChainLogId);
        wrapper.set(TransferCollectionWithoutRecords::getStatus, status);
        wrapper.set(StrUtil.isNotBlank(mateUniverseTransactionHash), TransferCollectionWithoutRecords::getMateUniverseTransactionHash, mateUniverseTransactionHash);
        wrapper.set(StrUtil.isNotBlank(mateWalletTransactionHash), TransferCollectionWithoutRecords::getMateWalletTransactionHash, mateWalletTransactionHash);
        update(new TransferCollectionWithoutRecords(), wrapper);
    }

    public TransferCollectionWithoutRecords getOneByUserCollectionChainLogIdAndStatus(Long userCollectionChainLogId,TransferCollectionWithoutStatusEnum status) {
        LambdaQueryWrapper<TransferCollectionWithoutRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TransferCollectionWithoutRecords::getUserCollectionChainLogId, userCollectionChainLogId);
        wrapper.eq(TransferCollectionWithoutRecords::getStatus, status);
        return getOne(wrapper);
    }

    public void updateStatusById(Long id, TransferCollectionWithoutStatusEnum status,String reqResult) {
        LambdaUpdateWrapper<TransferCollectionWithoutRecords> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(TransferCollectionWithoutRecords::getId, id);
        wrapper.set(TransferCollectionWithoutRecords::getStatus, status);
        wrapper.set(TransferCollectionWithoutRecords::getReqResult, reqResult);
        update(new TransferCollectionWithoutRecords(), wrapper);
    }

    public TransferCollectionWithoutRecords getOneByUserCollectionChainLogId(Long id) {
        LambdaQueryWrapper<TransferCollectionWithoutRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(TransferCollectionWithoutRecords::getUserCollectionChainLogId,id);
        return getOne(wrapper);
    }
}